# 使用命令
# python .\upload.py --file=C:\Users\Administrator\Downloads\com.daofeng.peiwan_3.9.0_55_1018140800.apk --branch=167fix
# python .\upload.py --file=C:\Users\Administrator\Downloads\com.ppyuewan.peiwan_1.7.1_86_0415173711.apk --branch=167fix --changelog=test


import argparse
import requests
import  platform

from requests_toolbelt import MultipartEncoder

parser = argparse.ArgumentParser(
    description='parallel distributed runner for robot framework')
parser.add_argument('--file', nargs='?', type=str,
                    help='please set file_path')
args = parser.parse_args()



def upload_apk():
    host = "http://116.62.196.25:9080"
    ## 完成登录
    # login_res = login()
    url = '{}/api/v1/upload'.format(host)
    file_path = args.file
    # file_path = 'E:\\play\\fabulove\\temp\\1683535373360-com.ppyuewan.peiwan_2.1.1.3_140_0427202538.apk'
    file_name = ''
    if platform.system().lower() == 'windows':
        print(platform.system())
        file_name = file_path.split('\\').pop()
    elif platform.system().lower() == 'linux':
        file_name = file_path.split('/').pop()
        print(platform.system())

    headers = {
                "Authorization": "f23f4f41538d2d4728ba7791fc733faca352f0be8ddf607acc2cef705648e6de"
              }
    m = MultipartEncoder(
        fields= {
            'name':'file',
            'filename':file_name,
            'file': (file_name, open(f'{file_path}', 'rb'),'application/vnd.android.package-archive')
        }
    )
    headers['Content-Type'] = m.content_type
    try:
        res = requests.post(url, data=m, headers=headers)
        print('upload End', res.text)
    except BaseException as e:
        print(e)


if __name__ == '__main__':
    upload_apk()

